package live.testdemo.bazi.controller;

import com.nlf.calendar.Lunar;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import live.testdemo.bazi.dao.entry.EightCharWangDu;
import live.testdemo.bazi.service.BaziService;
import lombok.RequiredArgsConstructor;

/**
 * @author zhoujianxin
 * @date 2023/1/27 00:20.
 */
@RestController
@RequestMapping
@RequiredArgsConstructor
public class EightCharController {
    private final BaziService baziService;

    @GetMapping("getWangDu")
    public EightCharWangDu getWangDu(@RequestParam String dateStr) {
        LocalDateTime date = LocalDateTime.parse(dateStr, DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
        Lunar lunar = Lunar.fromYmdHms(date.getYear(), date.getMonth().getValue(), date.getDayOfMonth(), date.getHour(), date.getMinute(), date.getSecond());
        return baziService.getWangDu(lunar);
    }
}
